package me.zhengjie.gas.rest;

import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.gas.model.ResponseDto;
import me.zhengjie.gas.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/api/report")
@Api(tags = "Report相关接口")
public class ReportController {
	@Autowired
	private ReportService service;

	@GetMapping("/saleDetailsByTimeRange")
	public ResponseDto get(@RequestParam("deptId") Long deptId,
	                       @RequestParam("startDate") String startDate,
	                       @RequestParam("endDate") String endDate) {
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
		return service.saleDetailsByTimeRange(deptId, LocalDateTime.parse(startDate, formatter),
				LocalDateTime.parse(endDate, formatter));
	}

	@GetMapping("/transactionByDateTimeRange")
	public ResponseDto transactionByDateTimeRange(@RequestParam("deptId") Long deptId,
	                                              @RequestParam("startDate") String startDate,
	                                              @RequestParam("endDate") String endDate) {
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
		return service.transactionByDateTimeRange(deptId, LocalDateTime.parse(startDate, formatter),
				LocalDateTime.parse(endDate, formatter));
	}

	@GetMapping("/oilSaleDetails")
	public ResponseDto oilSaleDetails(@RequestParam("deptId") Long deptId,
	                                  @RequestParam("startDate") String startDate,
	                                  @RequestParam("endDate") String endDate) {
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
		return service.oilSaleDetails(deptId, LocalDateTime.parse(startDate, formatter),
				LocalDateTime.parse(endDate, formatter));
	}

	@GetMapping("/allDeptSaleDetails")
	public ResponseDto allDeptSaleDetails(@RequestParam("deptId") Long deptId,
	                                      @RequestParam("startDate") String startDate,
	                                      @RequestParam("endDate") String endDate) {
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
		return service.allDeptSaleDetails(deptId, LocalDateTime.parse(startDate, formatter),
				LocalDateTime.parse(endDate, formatter));
	}

	@GetMapping("/lastYearSalesDetails")
	public ResponseDto lastYearSalesDetails(@RequestParam("deptId") Long deptId) {
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
		return service.lastYearSalesDetails(deptId);
	}

	@GetMapping("/todaySalesDetails")
	public ResponseDto todaySalesDetails(@RequestParam("deptId") Long deptId) {
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
		return service.todaySalesDetails(deptId);
	}

	@GetMapping("/monthSalesDetails")
	public ResponseDto monthSalesDetails(@RequestParam("deptId") Long deptId) {
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
		return service.monthSalesDetails(deptId);
	}

}
